<?php

$activityId = intval($_SESSION['SelectedActivity']);
$userType = $_SESSION["userType"];

if ($activityId != 0) {
    $qry = "SELECT ActivityName FROM activity WHERE ActivityId = '$activityId' ";
    $result = mysql_query($qry);
    while ($row = mysql_fetch_array($result)) {
        echo "<br><h3 style='font-size:18px'>" . $row['ActivityName'] . "</h3>";
    }

    $qry1 = "SELECT count(*)
	FROM activityrecord, activity, client, centre WHERE activityrecord.ActivityId = activity.ActivityId AND DATE(Date)=CURDATE() AND activityrecord.NRIC = client.NRIC AND activityrecord.CentreId = centre.CentreId AND activityrecord.ActivityId = '$activityId' ";
    $result1 = mysql_query($qry1);
    while ($row = mysql_fetch_array($result1)) {
        echo "<h3 style='vertical-align:right;text-align:right;font-size:18px'><b>Headcount: " . $row['count(*)'] . " </b></h3>";
    }
    if($userType!=="System Admin"){
    echo "<form  method='post'  name='submitForm' >
        <p><input type='submit' button value='Submit' name='btnSubmit' id='btnSubmit'></p>
        <?php
        
    ?>";}
    include 'conn.php';
    if ($_SESSION['userType'] == 'System Admin') {
        $result = mysql_query( "SELECT attendancerecord.NRIC, client.CustomerName, 
            centre.CentreName, attendancerecord.SignInTimeStamp
	FROM attendancerecord, client, centre 
        WHERE DATE(SignInTimeStamp)=CURDATE() 
        AND attendancerecord.NRIC = client.NRIC 
        AND attendancerecord.CentreId = centre.CentreId ");
    } else {
        $centreName = $_SESSION['centreName'];
        $result = mysql_query( "SELECT attendancerecord.NRIC, client.CustomerName, 
            centre.CentreName, attendancerecord.SignInTimeStamp
	FROM attendancerecord, client, centre 
        WHERE DATE(SignInTimeStamp)=CURDATE() 
        AND attendancerecord.NRIC = client.NRIC 
        AND attendancerecord.CentreId = centre.CentreId AND centre.CentreName='$centreName'");
    }

    echo "<p>
            </p><form name='cbForm' method='POST' id='cbForm'>
            <table class='tablereport' id='tblAttendance' border='5'  valign='top'><tr >
	<td name='Number'>
	<font face='Arial, Helvetica, sans-serif'>Number</font>
	</td>
	<td name='NRIC'>
	<font face='Arial, Helvetica, sans-serif'>NRIC</font>
	</td>
	<td name='CentreId'>
	<font face='Arial, Helvetica, sans-serif'>CustomerName</font>
	</td>
	<td name='CentreName' >
	<font face='Arial, Helvetica, sans-serif'>Centre Name</font>
	</td>
	<td name='Date' >
	<font face='Arial, Helvetica, sans-serif'>Date</font>
        </td>";
    if($userType!="System Admin"){
     echo"   <td>
        Participated<input type='checkbox' name='cball' id='cball' onClick='selectAll()' />
        </td>";
    }
    else
    {
        echo"   <td>
        Participated
        </td>";
    }
       echo" <td>
        Performance
        <br>1=Poor , 5=Excellent
        
        </td>
	</tr>";
    $count = 1;
    $cbCount = 1;
    while ($row = mysql_fetch_array($result)) {
        echo"<tr>
	<td >
	<font face='Arial, Helvetica, sans-serif'>" . $count . "</font>
	</td >
	<td >
	<font face='Arial, Helvetica, sans-serif'>" . $row['NRIC'] . "</font>
	</td >
	<td >
	<font face='Arial, Helvetica, sans-serif'>" . $row['CustomerName'] . "</font>
	</td>
	<td >
	<font face='Arial, Helvetica, sans-serif'>" . $row['CentreName'] . "</font>
	</td>
	<td>
	<font face='Arial, Helvetica, sans-serif'>" . $today = date('j F, Y') . "</font>
	</td>";

        $tempNRIC = $row['NRIC'];
        include 'conn.php';
        $result1 = mysql_query("SELECT  count(*) 
FROM activityrecord
WHERE NRIC =  '$tempNRIC'
AND ActivityId =  $activityId
AND date(Date) = CURDATE()");
        $row1 = mysql_fetch_array($result1);
        
            if ($row1['count(*)'] == 0) {
                if($userType!="System Admin"){
                echo "<td>
            <p style='text-align:center'>
        <input type='checkbox' name='cbpa[]' id='cbpa" . $row['NRIC'] . "' value='" . $row['NRIC'] . "-" . $cbCount . "'/></p>
        </td>";
                }
                else 
                {
                    echo"<td>
               <p style='text-align:center'> </p>
        </td>";
                }
            } else {

                echo"<td>
               <p style='text-align:center'>Yes</p>
        </td>";
            }
            
            
       
        $result2 = mysql_query("Select * from activityrecord where NRIC ='$tempNRIC' and ActivityId = $activityId and date(Date)=CURDATE()");
        $row2 = mysql_fetch_array($result2);
        
        if (mysql_num_rows($result2) == 1) {
            if (!($row2['Performance'] == null)) {
                echo "<td><p style='text-align:center;vertical-align:middle'>";
                echo $row2['Performance'];
                echo"   </p></td>";
            }
        } else {
            if($userType!="System Admin"){
            echo"
        <td>
        <p style='text-align:center'>
        1<input type='checkbox' name='cbpe" . $cbCount . "[]' value='1-" . $tempNRIC . "' id='1" . $cbCount . "' onClick='selectOne(this)'/>
        2<input type='checkbox' name='cbpe" . $cbCount . "[]' value='2-" . $tempNRIC . "'id='2" . $cbCount . "' onClick='selectOne(this)'/>
        3<input type='checkbox' name='cbpe" . $cbCount . "[]' value='3-" . $tempNRIC . "' id='3" . $cbCount . "'onClick='selectOne(this)'/>
        4<input type='checkbox' name='cbpe" . $cbCount . "[]' value='4-" . $tempNRIC . "' id='4" . $cbCount . "'onClick='selectOne(this)'/>
        5<input type='checkbox' name='cbpe" . $cbCount . "[]' value='5-" . $tempNRIC . "'id='5" . $cbCount . "' onClick='selectOne(this)'/></form>
        </p>
        </td>";
            $cbCount++;
            }
            else
            {
                echo "<td><p></p></td>";
            }
        }

        echo "</tr>";

        $count++;
    }
    $_SESSION["count"] = $count;

    echo "</table></form>";

} else {
    echo "<font color='red'>Please Select 1 activity!";
    include_once('ActivityAttendance/getattendance.php');
}
?>